public class insertion_sort {

    public static void sort(int[] arr) {
        int le = arr.length;
        for (int i = 1; i < le; i++) {
            for (int j = i; j - 1 >= 0 && arr[j] < arr[j - 1]; j--) {
                swap(arr, j, j -1);
            }
        }

    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }


    public static void main(String[] args) {
        int[] arr = {1, 4, 7, 34, 74, 5, 8, 3, 77, 8};
        sort(arr);
        print(arr);
    }
}
